package logic

import (
	"context"
	"fmt"

	"mall/service/mqueue/job/internal/svc"
	"mall/service/promotion/rpc/promotionclient"

	"github.com/hibiken/asynq"
)

type ScanPromotionCouponProcessor struct {
	svcCtx *svc.ServiceContext
}

func NewScanPromotionCouponProcessor(svcCtx *svc.ServiceContext) *ScanPromotionCouponProcessor {
	return &ScanPromotionCouponProcessor{
		svcCtx: svcCtx,
	}
}

// every one hour exec : if return err != nil , asynq will retry
func (l *ScanPromotionCouponProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error {
	_, err := l.svcCtx.PromotionRpc.ScanPromotionCoupon(ctx, &promotionclient.ScanPromotionCouponReq{
		PageSize: uint64(10),
	})
	if err != nil {
		return fmt.Errorf("ScanPromotionCouponProcessor err: %+v: %w ", err, asynq.SkipRetry)
	}

	return nil
}
